package controllers

import (
	// "encoding/json"
	"github.com/astaxie/beego"
	// "github.com/astaxie/beego/orm"
	"fmt"
)

type Register struct {
	beego.Controller
}

func (c *Register) Get() {
	c.Data["website"] = "beego.go"
	c.Data["email"] = "astaxie"
	c.TplName = "index.html"
}

func (c *Register) RetData(resp map[string]interface{}) {
	c.Data["json"] = resp
	c.ServeJSON()
}

func (this *Register) Reg() {
	// resp := make(map[string]interface{})
	// defer this.RetData(resp)

	// // 获取前端传过来的json的数据
	// json.Unmarshal(this.Ctx.Input.RequestBody, &resp)
	params := this.Ctx.Input.Params()
	username := ""
	if this.Ctx.GetCookie("username") == "" {
		this.Ctx.SetCookie("username", "aaa", 10)
	} else {
		username = this.Ctx.GetCookie("username") // cookie 不能为中文
	}

	this.SetSession("username", "admin")
	user := this.GetSession("username")
	
	fmt.Println(user)
	fmt.Println(params)
	this.Ctx.WriteString("username = " + username)

}
